package ex;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;

/**
 * @author: knowno
 * @create: 2025-09-16 10:08
 * @Version 1.0
 **/
public class TestIterator {
    public static void main(String[] args) {

        ArrayList list = new ArrayList<>();
        list.add("a");
        list.add("b");
        list.add("c");
        list.add("d");
        list.add("e");

        //Iterator<E> iterator()
        //boolean hasNext()
        //E next()

//        private class Itr implements Iterator<E>
        Iterator iterator = list.iterator();
        while (iterator.hasNext()){
            //next
            System.out.println(iterator.next());
        }
        System.out.println("*************************");

        LinkedList list1 = new LinkedList<>();
        list1.add("a");
        list1.add("b");
        list1.add("c");
        list1.add("d");
        list1.add("e");

        //Iterator<E> iterator()
        //boolean hasNext()
        //E next()
        //listIterator()
        Iterator iterator1 = list1.iterator();
        while (iterator1.hasNext()){
            //next
            System.out.println(iterator1.next());
        }
        System.out.println("*************************");

        HashSet<Object> objects = new HashSet<>();
        objects.add("a");
        objects.add("b");
        objects.add("c");
        objects.add("d");
        objects.add("e");

        //public Iterator<E> iterator() {
        //        return map.keySet().iterator();
        //    }

        Iterator<Object> iterator2 = objects.iterator();
        while (iterator2.hasNext()){
            System.out.println(iterator2.next());
        }

    }
}
